/**
 * For debugging I need being able drawing plots without extra movements 
 */
package common;

import java.io.File;
import java.io.IOException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 * @author vladimir
 * 
 */
public class Plot {
	public static void XYPlot(double[] y) {
		double[] x = new double[y.length];
		for (int i = 0; i < y.length; i++) {
			x[i] = i;
		}
		XYPlot(x, y);
	}

	public static void XYPlot(double[] x, double[] y) {
		if (x.length != y.length) {
			System.out.println("arrays should have same length");
			System.exit(1);
		}
		// Create a simple XY chart
		XYSeries series = new XYSeries("XYGraph");

		for (int i = 0; i < x.length; i++) {
			series.add(x[i], y[i]);
		}
		// Add the series to your data set
		XYSeriesCollection dataset = new XYSeriesCollection();
		dataset.addSeries(series);
		// Generate the graph
		JFreeChart chart = ChartFactory.createXYLineChart("XY Chart",
		// Title
				"x-axis",
				// x-axis Label
				"y-axis",
				// y-axis Label
				dataset,
				// Dataset
				PlotOrientation.VERTICAL, // Plot Orientation
				true,
				// Show Legend
				true,
				// Use tooltips
				false
		// Configure chart to generate URLs?
				);
		try {
			ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 1400,
					900);
		} catch (IOException e) {
			System.err.println("Problem occurred creating chart.");
		}

	}

}
